<script setup>
import bag from "../assets/mybag/bag-container.png";
import cardPic from "../assets/mybag/cardBg.png";
import { http } from "../services/service";
import { useUserStore } from "../store/index";
import { useI18n } from "vue-i18n";
import { ref } from "vue";
import cardList from "./components/cardList.vue";
import { dateFormat } from "../utils/util";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const back = () => {
  router.go(-1);
};

const i18nUse = useI18n();
const store = useUserStore();
const getHistory = (type) => {
  http
    .get(
      `/api/v1/center/myGroup?telegramId=${store?.getUser?.telegramId}&type=${type}`
    )
    .then(
      (response) => {
        const userLists = response?.data?.data?.userList;
        if (userLists?.length) {
          historyList.value = userLists;
        } else {
          historyList.value = [];
        }
      },
      () => {}
    );
};
getHistory("zt");
const onClickTab = (e) => {
  if (e.name === 0) {
    getHistory("zt");
  }
  if (e.name === 1) {
    getHistory("jt");
  }
  if (e.name === 2) {
    getHistory("gl");
  }
};
const historyList = ref([]);
const background = `url(${bag})`;
</script>

<template>
  <div class="container">
    <div class="title">
      <van-icon
        name="arrow-left"
        class="icon-left"
        size="25"
        @click="back()"
      />{{ $t("myTeam") }}
    </div>
    <div class="container-tab">
      <van-tabs
        v-model:active="active"
        :background="background"
        color="#fff"
        title-active-color="#fff"
        title-inactive-color="#9699A2"
        @click-tab="onClickTab"
      >
        <van-tab :title="$t('directPush')">
          <!-- <div class="container-score">
            <div style="margin-top: 16px" class="start-container">
              <div
                class="part"
                style="
                  width: calc(50% - 10px);
                  border-right: 2px solid #555862;
                  border-color: rgba(85, 88, 98, 0.6);
                "
              >
                <div class="part-title">{{ $t("totalCount") }}</div>
                <div class="part-num">
                 12
                </div>
              </div>
              <div class="part" style="text-align: center">
                <div class="part-title">{{ $t("districtCount") }}</div>
                <div class="part-num">
                 13
                </div>
              </div>
            </div>
          </div> -->
          <div class="container-history">
            <div class="list" style="color: #7a7b83; border: none">
              <div style="text-align: center">UID</div>
              <div style="text-align: center">{{ $t("nickName") }}</div>
              <div style="text-align: center">{{ $t("registerTime") }}</div>
            </div>
            <div v-for="history in historyList" class="list">
              <div>
                {{ history.telegramId }}
              </div>
              <div style="text-align: center">
                {{ history.nickName }}
              </div>
              <div style="text-align: center">
                {{ dateFormat(history.createTime) }}
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab :title="$t('indirectPush')">
          <!-- <div class="container-score">
            <div style="margin-top: 16px" class="start-container">
              <div
                class="part"
                style="
                  width: calc(50% - 10px);
                  border-right: 2px solid #555862;
                  border-color: rgba(85, 88, 98, 0.6);
                "
              >
                <div class="part-title">{{ $t("totalCount") }}</div>
                <div class="part-num">
                 12
                </div>
              </div>
              <div class="part" style="text-align: center">
                <div class="part-title">{{ $t("districtCount") }}</div>
                <div class="part-num">
                 13
                </div>
              </div>
            </div>
          </div> -->
          <div class="container-history">
            <div class="list" style="color: #7a7b83; border: none">
              <div style="text-align: center">UID</div>
              <div style="text-align: center">{{ $t("nickName") }}</div>
              <div style="text-align: center">{{ $t("registerTime") }}</div>
            </div>
            <div v-for="history in historyList" class="list">
              <div style="text-align: center">
                {{ history.telegramId }}
              </div>
              <div style="text-align: center">
                {{ history.nickName }}
              </div>
              <div style="text-align: center">
                {{ dateFormat(history.createTime) }}
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab :title="$t('manage')">
          <!-- <div class="container-score">
            <div style="margin-top: 16px" class="start-container">
              <div
                class="part"
                style="
                  width: calc(50% - 10px);
                  border-right: 2px solid #555862;
                  border-color: rgba(85, 88, 98, 0.6);
                "
              >
                <div class="part-title">{{ $t("totalCount") }}</div>
                <div class="part-num">
                 12
                </div>
              </div>
              <div class="part" style="text-align: center">
                <div class="part-title">{{ $t("districtCount") }}</div>
                <div class="part-num">
                 13
                </div>
              </div>
            </div>
          </div> -->
          <div class="container-history">
            <div class="list" style="color: #7a7b83; border: none">
              <div style="text-align: center">UID</div>
              <div style="text-align: center">{{ $t("nickName") }}</div>
              <div style="text-align: center">{{ $t("registerTime") }}</div>
            </div>
            <div v-for="history in historyList" class="list">
              <div style="text-align: center">
                {{ history.telegramId }}
              </div>
              <div style="text-align: center">
                {{ history.nickName }}
              </div>
              <div style="text-align: center">
                {{ dateFormat(history.createTime) }}
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<style scoped lang="less">
.container-score {
  width: calc(100% - 32px);
  margin: 20px auto 0 auto;
  height: 90px;
  padding: 10px 0;
  border: 1px solid #9aa7ff;
  border-radius: 10px;
  background: rgba(48, 55, 90, 0.6);

  .start-title {
    font-size: 12px;
    padding: 0 22px;
  }

  .start-container {
    display: flex;
    padding: 0 22px;
    justify-content: space-between;

    .part {
      width: 50%;

      .part-title {
        font-size: 15px;
        font-weight: bold;
        color:#95969C;
      }

      .part-num {
        margin-top: 7px;
        color: #ffffff;
        font-size: 24px;
        font-family: dinBold;
        font-weight: 700;
      }
    }
  }
}
.container {
  background: url("../assets/home-page-bg.png");
  width: 100%;
  min-height: 100vh;
  padding-bottom: 100px;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  color: #fff;
}

.container-history {
  width: 80%;
  margin: 20px auto;
  min-height: 50px;
  border-radius: 10px;

  .list {
    display: flex;
    padding-bottom: 10px;
    justify-content: space-between;
    border-bottom: 1px solid #20222e;
    border-color: rgba(255, 255, 255, 0.1);
    margin-top: 14px;
    font-weight: 400;
    font-size: 14px;

    > div {
      width: 32%;
      display: flex;
      align-items: center;
    }
  }
}

.title {
  .icon-left {
    position: absolute !important;
    left: 16px;
    top: 8px;
    cursor: pointer;
  }

  font-size: 17px;
  text-align: center;
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
}

.container-tab {
  margin-top: 30px;
}
</style>
